#include <bits/stdc++.h>

using namespace std;

const int MAXN = 2010;
const int mod = 1e9+7;

typedef long long ll;

bool vis[MAXN];
ll f[MAXN][MAXN];
int a[MAXN],n,k,m;

int main (){
	scanf("%d",&n);m = n;
	for(int i = 1;i <= n;i++) {
		scanf("%d",&a[i]);
		if(a[i] != -1) vis[a[i]] = 1,m--;
	}
	for(int i = 1;i <= n;i++) if(a[i] == - 1 && !vis[i]) k++;
	for(int i = (f[0][0] = 1);i <= m;i++) f[i][0] = f[i-1][0] * i % mod;
	for(int i = 1;i <= m;i++)
		for(int j = 1;j <= k;j++)
			f[i][j] = (f[i][j-1] - f[i-1][j-1] + mod) % mod;
	printf("%lld\n",f[m][k]); return 0;
}
